// 引入mockjs
import Mock from "mockjs";

// 获取 mock.Random 对象
const Random = Mock.Random;

// 使用mockjs模拟数据
let tableList = [
    {
        id: "5ffa80aD-9CF4-0C77-eBFC-f6612BfAcF4F",
        account: "admin",
        password: "123456",
        address: "36918166@qq.com",
    },
    {
        id: "4FcC922C-C72c-95c3-Ef92-FbFAc24cc831",
        account: "ebHoL6",
        password: "i320Hu74fbn2Gi",
        address: "48165263@qq.com",
    },
]

let treeData = [{
    id: 1,
    name: '一级 1',
    children: [{
        id: 4,
        name: '二级 1-1',
        children: [{
            id: 9,
            name: '三级 1-1-1'
        }, {
            id: 10,
            name: '三级 1-1-2'
        }]
    }]
}, {
    id: 2,
    name: '一级 2',
    children: [{
        id: 5,
        name: '二级 2-1'
    }, {
        id: 6,
        name: '二级 2-2'
    }]
}, {
    id: 3,
    name: '一级 3',
    children: [{
        id: 7,
        name: '二级 3-1'
    }, {
        id: 8,
        name: '二级 3-2'
    }]
}]

let userList = [
    {id: 1, name: '健', personStatus: '0'}, {id: 2, name: '蕾', personStatus: '0'},
    {id: 3, name: '丽', personStatus: '0'}, {id: 4, name: '洁', personStatus: '0'},
    {id: 5, name: '颖', personStatus: '0'}, {id: 6, name: '佳', personStatus: '0'},
    {id: 7, name: '珍', personStatus: '0'}]

// for (let i = 0; i < 20; i++) {
//   let newObject = {
//     id: Random.guid(), // 获取全局唯一标识符
//     account: /^[a-zA-Z0-9]{4,6}$/,
//     password: /^[a-zA-Z]\w{5,17}$/,
//     address: /[1-9]\d{7,10}@qq\.com/,
//   };
//   tableList.push(newObject);
// }

Mock.mock("/api/mockTreeList", "get", () => {
    return {
        code: "0",
        data: treeData,
    };

});

Mock.mock("/api/mockOrgUserList", "get", () => {
    return {
        code: "0",
        data: userList,
    };

});

/** get请求
 * 获取用户列表
 */
Mock.mock("/api/mockGetList", "get", () => {
    return {
        code: "0",
        data: tableList,
    };

});


/** post请求添加表格数据 */
Mock.mock("/api/add", "post", (params) => {
    let newData = JSON.parse(params.body);
    newData.id = Random.guid();
    tableList.push(newData);
    return {
        code: "0",
        message: "success",
        data: tableList,
    };
});